package com.example.wallpaperapp.utils;

import android.content.Context;
import android.text.TextUtils;
import android.widget.TextView;
import android.widget.Toast;

import com.example.wallpaperapp.widget.CountDownTextView;

public class PhoneNumberUtils {
    /**
     * 判断手机号
     * @param context
     * @param textView
     * @param phoneNums 手机号
     * @return
     */
    public static boolean judgePhoneNums(Context context, TextView textView, String phoneNums){
        CountDownTextView timer;
        if (isMatchLength(phoneNums,11)&&isMobile(phoneNums)){
            timer=new CountDownTextView(60000,1000,textView,context);
            timer.start();
            return true;
        }
        Toast.makeText(context, "手机号输入有误！", Toast.LENGTH_SHORT).show();
        return false;
    }
    public static boolean judgePhoneNums(Context context,  String phoneNums){
        if (isMatchLength(phoneNums,11)&&isMobile(phoneNums)){
            return true;
        }
        Toast.makeText(context, "手机号输入有误！", Toast.LENGTH_SHORT).show();
        return false;
    }

    /**
     * 判断string字符串的位数
     */
    private static boolean isMatchLength(String str,int len){
        if (str.isEmpty()){
            return false;
        }else {
            return str.length()==len?true:false;
        }
    }
    /**
     * 判断手机号格式
     */
    private static boolean isMobile(String moubleNUms){
        String telRegex="[1][35789]\\d{9}";
        if (TextUtils.isEmpty(telRegex))
            return false;
        else
            return moubleNUms.matches(telRegex);
    }
}
